from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-12 14:03:27.009102
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 12, Aug, 2022
Time: 14:03:33
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1118
Nobs: 746.000 HQIC: -50.4539
Log likelihood: 9462.60 FPE: 9.88443e-23
AIC: -50.6685 Det(Omega_mle): 8.76809e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.294052 0.055363 5.311 0.000
L1.Burgenland 0.108375 0.036756 2.948 0.003
L1.Kärnten -0.106728 0.019486 -5.477 0.000
L1.Niederösterreich 0.208359 0.076666 2.718 0.007
L1.Oberösterreich 0.109298 0.074879 1.460 0.144
L1.Salzburg 0.254384 0.039269 6.478 0.000
L1.Steiermark 0.040879 0.051266 0.797 0.425
L1.Tirol 0.107515 0.041584 2.585 0.010
L1.Vorarlberg -0.061658 0.035668 -1.729 0.084
L1.Wien 0.050320 0.066223 0.760 0.447
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060844 0.115639 0.526 0.599
L1.Burgenland -0.033395 0.076774 -0.435 0.664
L1.Kärnten 0.047114 0.040702 1.158 0.247
L1.Niederösterreich -0.176077 0.160134 -1.100 0.272
L1.Oberösterreich 0.407527 0.156402 2.606 0.009
L1.Salzburg 0.287763 0.082023 3.508 0.000
L1.Steiermark 0.108083 0.107081 1.009 0.313
L1.Tirol 0.312068 0.086858 3.593 0.000
L1.Vorarlberg 0.024563 0.074501 0.330 0.742
L1.Wien -0.030891 0.138322 -0.223 0.823
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188181 0.028411 6.623 0.000
L1.Burgenland 0.090077 0.018863 4.775 0.000
L1.Kärnten -0.008774 0.010000 -0.877 0.380
L1.Niederösterreich 0.259919 0.039343 6.606 0.000
L1.Oberösterreich 0.138004 0.038427 3.591 0.000
L1.Salzburg 0.045566 0.020152 2.261 0.024
L1.Steiermark 0.020832 0.026309 0.792 0.428
L1.Tirol 0.093049 0.021340 4.360 0.000
L1.Vorarlberg 0.056598 0.018304 3.092 0.002
L1.Wien 0.117674 0.033985 3.463 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107428 0.028885 3.719 0.000
L1.Burgenland 0.045607 0.019177 2.378 0.017
L1.Kärnten -0.013769 0.010167 -1.354 0.176
L1.Niederösterreich 0.189878 0.039999 4.747 0.000
L1.Oberösterreich 0.301230 0.039067 7.711 0.000
L1.Salzburg 0.109747 0.020488 5.357 0.000
L1.Steiermark 0.103450 0.026747 3.868 0.000
L1.Tirol 0.105515 0.021696 4.863 0.000
L1.Vorarlberg 0.069259 0.018609 3.722 0.000
L1.Wien -0.019170 0.034551 -0.555 0.579
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126761 0.052579 2.411 0.016
L1.Burgenland -0.050402 0.034908 -1.444 0.149
L1.Kärnten -0.040638 0.018506 -2.196 0.028
L1.Niederösterreich 0.172055 0.072810 2.363 0.018
L1.Oberösterreich 0.138452 0.071113 1.947 0.052
L1.Salzburg 0.288860 0.037294 7.745 0.000
L1.Steiermark 0.035587 0.048688 0.731 0.465
L1.Tirol 0.163373 0.039493 4.137 0.000
L1.Vorarlberg 0.099796 0.033874 2.946 0.003
L1.Wien 0.068237 0.062893 1.085 0.278
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056747 0.041794 1.358 0.175
L1.Burgenland 0.039150 0.027748 1.411 0.158
L1.Kärnten 0.051251 0.014710 3.484 0.000
L1.Niederösterreich 0.219039 0.057875 3.785 0.000
L1.Oberösterreich 0.294169 0.056527 5.204 0.000
L1.Salzburg 0.043725 0.029645 1.475 0.140
L1.Steiermark 0.000104 0.038701 0.003 0.998
L1.Tirol 0.143484 0.031392 4.571 0.000
L1.Vorarlberg 0.072165 0.026926 2.680 0.007
L1.Wien 0.081076 0.049992 1.622 0.105
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174203 0.049945 3.488 0.000
L1.Burgenland -0.002467 0.033159 -0.074 0.941
L1.Kärnten -0.062511 0.017579 -3.556 0.000
L1.Niederösterreich -0.077044 0.069163 -1.114 0.265
L1.Oberösterreich 0.189009 0.067551 2.798 0.005
L1.Salzburg 0.058219 0.035426 1.643 0.100
L1.Steiermark 0.234392 0.046249 5.068 0.000
L1.Tirol 0.498781 0.037515 13.296 0.000
L1.Vorarlberg 0.044690 0.032177 1.389 0.165
L1.Wien -0.054936 0.059742 -0.920 0.358
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160708 0.057745 2.783 0.005
L1.Burgenland -0.008853 0.038337 -0.231 0.817
L1.Kärnten 0.066528 0.020325 3.273 0.001
L1.Niederösterreich 0.206439 0.079963 2.582 0.010
L1.Oberösterreich -0.069943 0.078100 -0.896 0.370
L1.Salzburg 0.210898 0.040959 5.149 0.000
L1.Steiermark 0.120548 0.053471 2.254 0.024
L1.Tirol 0.072668 0.043373 1.675 0.094
L1.Vorarlberg 0.119317 0.037202 3.207 0.001
L1.Wien 0.123090 0.069072 1.782 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.358763 0.033107 10.836 0.000
L1.Burgenland 0.006988 0.021980 0.318 0.751
L1.Kärnten -0.023438 0.011653 -2.011 0.044
L1.Niederösterreich 0.214659 0.045846 4.682 0.000
L1.Oberösterreich 0.198899 0.044777 4.442 0.000
L1.Salzburg 0.044248 0.023483 1.884 0.060
L1.Steiermark -0.013810 0.030657 -0.450 0.652
L1.Tirol 0.104352 0.024867 4.196 0.000
L1.Vorarlberg 0.071499 0.021329 3.352 0.001
L1.Wien 0.039766 0.039601 1.004 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038982 0.139779 0.191981 0.150998 0.117729 0.102990 0.064181 0.216993
Kärnten 0.038982 1.000000 -0.007453 0.132084 0.039457 0.094227 0.432801 -0.053667 0.097229
Niederösterreich 0.139779 -0.007453 1.000000 0.334354 0.141678 0.293068 0.096137 0.180365 0.313278
Oberösterreich 0.191981 0.132084 0.334354 1.000000 0.228303 0.325790 0.176090 0.167458 0.261430
Salzburg 0.150998 0.039457 0.141678 0.228303 1.000000 0.142656 0.112872 0.145363 0.123916
Steiermark 0.117729 0.094227 0.293068 0.325790 0.142656 1.000000 0.146655 0.137746 0.071090
Tirol 0.102990 0.432801 0.096137 0.176090 0.112872 0.146655 1.000000 0.112605 0.142525
Vorarlberg 0.064181 -0.053667 0.180365 0.167458 0.145363 0.137746 0.112605 1.000000 0.002364
Wien 0.216993 0.097229 0.313278 0.261430 0.123916 0.071090 0.142525 0.002364 1.000000